import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css'
import locale from 'element-plus/es/locale/lang/zh-cn' // element-ui plus 显示中文
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import router from '@/rooter'
import store from '@/store'

const app = createApp(App);


const debounce = (fn, delay) => {
   let timer = null;
   return function () {
      let context = this;
      let args = arguments;
      clearTimeout(timer);
      timer = setTimeout(function () {
         fn.apply(context, args);
      }, delay);
   }
}

const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
   constructor(callback) {
      callback = debounce(callback, 16);
      super(callback);
   }
}

// 注册element-ui plus的icon图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
   app.component(key, component)
}

app.use(ElementPlus, { locale }).use(router).use(store);
app.mount('#app');


